package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.PromotionBean;
import com.lwj.liwanjia.impl.PromotionView;
import com.lwj.liwanjia.model.PromotionModel;

import rx.Subscriber;

/**
 * Created by Administrator on 2017/9/10.
 */

public class PromotionPresenter {
    private PromotionModel promotionModel;
    private PromotionView promotionView;

    public PromotionPresenter(PromotionView promotionView) {
        this.promotionView = promotionView;
        promotionModel = new PromotionModel();
    }

    public void getPromotionData() {
        if (promotionView != null) {
            promotionModel.getPromotionData(new Subscriber<PromotionBean>() {
                @Override
                public void onCompleted() {
                    promotionView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    promotionView.showError((Exception) e);
                    promotionView.hideProgress();
                }

                @Override
                public void onNext(PromotionBean promotionBean) {
                    promotionView.getPromotionData(promotionBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    promotionView.showProgress();
                }
            });
        }
    }
}
